import { Body, Controller, Get, Inject, Post, Query } from '@midwayjs/core';
import { NumService } from '../service/num.service';
import { AssignNumDto, NumPageQueryDto } from '../dto/num.dto';

@Controller('/auth-api/num')
export class NumController {
  @Inject()
  numService: NumService;

  @Get('/list/available')
  async getAvailableNums() {
    return await this.numService.getAvailableNums();
  }

  /**
   * 查询已分配编号
   * @param sellerId 经销商ID
   * @returns
   */
  @Get('/list/assigned')
  async getAssignedNums(@Query('sellerId') sellerId?: number) {
    return await this.numService.getAssignedNumbers(sellerId);
  }

  @Post('/assign')
  async assignNums(@Body() dto: AssignNumDto) {
    return await this.numService.assignNums(dto);
  }

  @Post('/add/batch')
  async batchAddNums(
    @Body('min')
    min: number,
    @Body('max')
    max?: number
  ) {
    return await this.numService.addNums(min, max);
  }

  @Get('/list/page')
  async getNumPageList(@Query() dto: NumPageQueryDto) {
    return await this.numService.getNumPageList(dto);
  }

  @Get('/max')
  async getMaxNumber() {
    return await this.numService.getMaxNumber();
  }
}
